package com.hhd.cwqs.jobs;

import com.hhd.cwqs.qs.CwqsDelegate;
import com.hhd.cwqs.utils.CommonUtils;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

@DisallowConcurrentExecution
public class CwqsJob implements Job {

    @Autowired
    IQuartzJobService jobService;

    @Autowired
    CwqsDelegate cwqsDelegate;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        String jobKey = context.getJobDetail().getKey().getName();
        QuartzJob job = jobService.getById(jobKey);
        if (CommonUtils.isEmpty(job)) {
            Object o = context.getMergedJobDataMap().get("parameter");
            if (!CommonUtils.isEmpty(o)) {
                job = jobService.getById(o.toString());
            }
        }
        if (!CommonUtils.isEmpty(job)) {
            cwqsDelegate.qsByJob(job);
        } else {
            throw new RuntimeException("没有找到定时任务的配置!");
        }
    }
}